import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:top_foundation/component/page_state/widgets/empty.dart';
import 'package:whale/helper/utils/util.dart';

import '../index.dart';

/// hello
class SearchHistoryCell extends GetView<SearchController> {
  const SearchHistoryCell({
    Key? key,
    required this.text,
  }) : super(key: key);
  final String text;

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {
        controller.actionHistoryCell(text);
      },
      child: Container(
        padding: EdgeInsets.only(left: 12.r),
        decoration: const BoxDecoration(
          border: Border(
            bottom: BorderSide(color: ColorsUtil.separator, width: 0.5),
          ),
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Expanded(
              child: Padding(
                padding: EdgeInsets.symmetric(
                  vertical: 10.r,
                ),
                child: Text(
                  text,
                  style: TextStyle(
                    color: ColorsUtil.title,
                    fontSize: 13.sp,
                  ),
                ),
              ),
            ),
            InkWell(
              onTap: () => controller.actionDelItem(text),
              child: Container(
                height: 36.r,
                padding: EdgeInsets.symmetric(horizontal: 12.r),
                child: Icon(
                  IconUtil.wrong,
                  size: 10.r,
                  color: ColorsUtil.content,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class SearchHistoryView extends GetView<SearchController> {
  const SearchHistoryView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var state = controller.state;
    return Column(
      children: [
        Container(
          height: 40.r,
          padding: EdgeInsets.only(left: 12.r),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                '搜索历史记录',
                style: TextStyle(
                  color: ColorsUtil.content,
                  fontSize: 13.sp,
                ),
              ),
              InkWell(
                onTap: controller.actionDel,
                child: Container(
                  height: 40.r,
                  padding: EdgeInsets.symmetric(horizontal: 12.r),
                  child: Row(
                    children: [
                      loadImage(url: 'clean.png'.imgPathMeans, width: 14.r),
                      const SizedBox(
                        width: 3,
                      ),
                      Text(
                        '清除',
                        style:
                            TextStyle(color: ColorsUtil.theme, fontSize: 13.sp),
                      )
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
        Expanded(
          child: isZeroList(state.historys)
              ? const EmptyView(
                  title: '没有历史记录',
                  url: 'assets/jsons/not_found.json',
                  isLottie: true,
                )
              : ListView(
                  children: state.historys!
                      .map((e) => SearchHistoryCell(text: e))
                      .toList(),
                ),
        ),
      ],
    );
  }
}
